package com.wyq.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wyq.dao.AdminMenuDAO;
import com.wyq.util.impl.JDBCDAOSupportImpl;

public class AdminMenuDAOImpl extends JDBCDAOSupportImpl implements AdminMenuDAO {
	
	//查询父菜单
	public List findParentMenu() throws Exception{
		List menuList = new ArrayList();
		String sql = "select * from admin_menu where parentid = 0";
		List adminMenuList = this.getListMapBySql(sql);
		
		for(int i=0;i<adminMenuList.size();i++){
			Map adminMenuMap = (Map) adminMenuList.get(i);
			//menuMap.put("id", adminMenu.getId());
			//menuMap.put("parentid", adminMenu.getParentid());
			//menuMap.put("text", adminMenu.getMenutext());
			//System.out.println("-------" + adminMenuMap.get("id"));
			List subMenuList = this.findSubMenu(adminMenuMap.get("id").toString());
			adminMenuMap.put("children", subMenuList);
			menuList.add(adminMenuMap);
		}
		return menuList;
	}
	//查询子菜单
	public List findSubMenu(String parentId) throws Exception {
		String sql = "select * from admin_menu where parentid = " + parentId;
		List list = this.getListMapBySql(sql);
		return list;
	}
	
	
	

}
